package com.gecco;

import com.geccocrawler.gecco.annotation.PipelineName;
import com.geccocrawler.gecco.pipeline.Pipeline;
import com.geccocrawler.gecco.request.HttpRequest;
import com.geccocrawler.gecco.scheduler.SchedulerContext;
import org.apache.http.util.TextUtils;

@PipelineName(value="doutusheIndex")
public class FinishDoutusheIndex implements Pipeline<DoutuSheIndex> {

    @Override
    public void process(DoutuSheIndex doutusheIndex) {


        //首先遍历帖子的详情
        for (int i = 0; i < doutusheIndex.getIdList().size(); i++) {
            if (!TextUtils.isEmpty(doutusheIndex.getNameList().get(i))) {
                String url = doutusheIndex.getIdList().get(i);

                HttpRequest currRequest = doutusheIndex.getRequest();
                SchedulerContext.into(currRequest.subRequest(url));
            }
        }
        //跳转到下一页

        for (int i = 0; i < doutusheIndex.getPageList().size(); i++) {
            String pageName = doutusheIndex.getPageList().get(i).getPageName();

            if (pageName != null && pageName.equals("下一页")) {
                String url = doutusheIndex.getPageList().get(i).getPageUrl();
                HttpRequest currRequest = doutusheIndex.getRequest();

                SchedulerContext.into(currRequest.subRequest(url));
            }
        }


    }
}